package com.kedacom.demo.modularity.message;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class XMPPMessageGatewayJAXRSClientTest {

	protected static Logger logger = LoggerFactory.getLogger(XMPPMessageGatewayJAXRSClientTest.class);

	protected static XMPPMessageGateway xmppMessageGateway;
	protected static String url = "http://127.0.0.1:8080/message/rest";
	private static ClassPathXmlApplicationContext context;

	// @BeforeClass
	public static void setUp() throws InterruptedException {
		// Thread emailServer = new Thread(new XMPPMessageGatewayRunnable(url));
		// emailServer.start();
		// Thread.sleep(15000);

		context = new ClassPathXmlApplicationContext("/spring-message-jaxrs-client.xml");
		xmppMessageGateway = context.getBean(XMPPMessageGateway.class);
	}

	// @AfterClass
	public static void tearDown() {
		context.close();
	}

	// @Test
	public void testPublish() throws InterruptedException {
		for (int i = 0; i < 100; i++) {
			new Thread(new ClientTestRunnable(xmppMessageGateway)).start();
			Thread.sleep(10);
		}
		Thread.sleep(5000);
	}

	public static void main(String[] args) throws InterruptedException {
		try {
			setUp();
			while (true) {
				new ClientTestRunnable(xmppMessageGateway).run();
				Thread.sleep(1000);
			}
		} finally {
			tearDown();
		}
	}

}
